<!-- eslint-disable no-console -->
<script lang="ts" setup>
// import type { VxeFormListeners, VxeFormProps } from '@vben/plugins/vxe-table';

import { ref } from 'vue';

import { useVbenModal } from '@vben/common-ui';

// import { VxeUI } from '@vben/plugins/vxe-table';
import { useVbenForm } from '#/adapter/form';

const data = ref();
const mes_index_type = ref();
const mes_qc_result_type = ref();

const [Modal, modalApi] = useVbenModal({
  onOpenChange(isOpen: boolean) {
    if (isOpen) {
      data.value = modalApi.getData();
      if (data.value) {
        if (data.value.row) {
          baseFormApi.setValues(data.value.row);
        }
        mes_index_type.value = data.value.mes_index_type;
        mes_qc_result_type.value = data.value.mes_qc_result_type;
        // sexItemRender.options = mes_qc_result_type.value;
      }
    }
  },
});

const [BaseForm, baseFormApi] = useVbenForm({
  // 所有表单项共用，可单独在表单内覆盖
  resetButtonOptions: {
    show: false,
  },
  commonConfig: {
    // 所有表单项
    componentProps: {
      class: 'w-full',
    },
  },
  // 提交函数
  handleSubmit: onSubmit,
  // 垂直布局，label和input在不同行，值为vertical
  // 水平布局，label和input在同一行
  layout: 'horizontal',
  schema: [
    {
      // 组件需要在 #/adapter.ts内注册，并加上类型
      component: 'Input',
      rules: 'required',
      // 对应组件的参数
      componentProps: {
        placeholder: '请输入检测项编码',
      },
      // 字段名
      fieldName: 'indexCode',
      // 界面显示的label
      label: '检测项编码',
    },
    {
      component: 'Input',
      rules: 'required',
      componentProps: {
        placeholder: '请输入检测项名称',
      },
      fieldName: 'indexName',
      label: '检测项名称',
    },
    {
      component: 'Select',
      rules: 'required',
      componentProps: {
        allowClear: true,
        filterOption: true,
        options: mes_index_type,
        placeholder: '请选择',
        showSearch: true,
      },
      fieldName: 'indexType',
      label: '检测项类型',
    },
    {
      component: 'Input',
      componentProps: {
        placeholder: '请输入检测工具',
      },
      fieldName: 'qcTool',
      label: '检测工具',
    },
    {
      component: 'Select',
      rules: 'required',
      componentProps: {
        allowClear: true,
        filterOption: true,
        options: mes_qc_result_type,
        placeholder: '请选择',
        showSearch: true,
      },
      fieldName: 'qcResultType',
      label: '检测值类型',
    },
    {
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入内容',
      },
      formItemClass: 'col-span-2',
      fieldName: 'remark',
      label: '备注',
    },
  ],
  wrapperClass: 'grid-cols-1 md:grid-cols-2',
});

function onSubmit(values: Record<string, any>) {
  console.log(values);

  modalApi.close();
}
// const sexItemRender = reactive<VxeFormItemPropTypes.ItemRender>({
//   name: 'VxeSelect',
// });

// const formOptions = reactive<VxeFormProps<QcindexApi.Row>>({
//   validConfig: {
//     theme: 'normal',
//   },
//   data: {
//     searchValue: null,
//     createBy: '',
//     createTime: '',
//     updateBy: '',
//     updateTime: null,
//     remark: '',
//     params: {},
//     indexId: 0,
//     indexCode: '',
//     indexName: '',
//     indexType: '',
//     qcTool: null,
//     qcResultType: '',
//     qcResultSpc: null,
//     attr1: null,
//     attr2: null,
//     attr3: 0,
//     attr4: 0,
//   },
//   rules: {
//     indexCode: [{ required: true, message: '请输入检测项编码' }],
//     indexName: [{ required: true, message: '请输入检测项名称' }],
//     indexType: [{ required: true, message: '请选择' }],
//     qcTool: [{ message: '请输入检测工具' }],
//     qcResultType: [{ required: true, message: '请选择' }],
//   },
//   items: [
//     {
//       field: 'indexCode',
//       title: '检测项编码',
//       span: 12,
//       itemRender: { name: 'VxeInput' },
//     },
//     {
//       field: 'indexName',
//       title: '检测项名称',
//       span: 12,
//       itemRender: { name: 'VxeInput' },
//     },
//     {
//       field: 'indexType',
//       title: '检测项类型',
//       span: 12,
//       itemRender: sexItemRender,
//     },
//     {
//       field: 'qcResultType',
//       title: '检测值类型',
//       span: 12,
//       itemRender: sexItemRender,
//     },
//     {
//       field: 'qcTool',
//       title: '检测工具',
//       span: 12,
//       itemRender: { name: 'VxeInput' },
//     },
//     {
//       field: 'remark',
//       title: '备注',
//       span: 24,
//       itemRender: { name: 'VxeTextarea' },
//     },
//     {
//       align: 'center',
//       span: 24,
//       itemRender: {
//         name: 'VxeButtonGroup',
//         options: [{ type: 'submit', content: '提交', status: 'primary' }],
//       },
//     },
//   ],
// });

// const formEvents: VxeFormListeners<QcindexApi.Row> = {
//   submit() {
//     VxeUI.modal.message({ content: '保存成功', status: 'success' });
//   },
// };
</script>
<template>
  <Modal class="w-4/6">
    <!-- <VxeForm v-bind="formOptions" v-on="formEvents" /> -->
    <BaseForm />
  </Modal>
</template>
